#!/bin/bash
if [ $# -eq 0 ];then
	echo "usage:$0 -f <filepath> -l <wordlen> [-c <cmp:==|>|<>]"
　　exit 1
fi

file=''
wl=0
cmp='=='
until [ $# -eq 0 ];
do
	if [ $1 == '-f' ];then
		shift
		file=$1
	fi
	if [ $1 == '-l' ];then
		shift
		wl=$1
	fi
	if [ $1 == '-c' ];then
		shift
		cmp=$1
	fi
	shift
done 

if [ ! -f $file ];then
	echo "$file not exsit"
	exit 2
fi

if [ $wl -lt 3 -o $wl -gt 36 ];then
	echo "wordlen should between 3 and 36"
	exit 3
fi

if [ $cmp != '==' -a $cmp != '<' -a $cmp != '>' ];then
	echo "cmp should be == or > or <"
	exit 4
fi

sed -i 's/\r//g' $file
perl -ne 'chomp($_); @wf=split(/\s/, $_, 2); next LINE unless(length($wf[0])'"$cmp $wl"'); if($#wf == 0){$wf[1]=1;} print $wf[0]."\t".$wf[1]."\n"' $file

